#include "include.h"
#include "bsp_led.h"

#define MAX_GRB_LED 8
light_info_t light_info;
u8 rgb_light_buf[8];
disp_status_t grow_info;
u32 delay_ticks=0;
u8 prev_level;

AT(.com_text.light_disp.table)
const u8 bt_connected_color_table[8]=
{
	RGB_COLOR_RED,
	RGB_COLOR_PINK,
	RGB_COLOR_PURPLE,
	RGB_COLOR_YELLOW,
	RGB_COLOR_ORANGE,	
	RGB_COLOR_LIGHT_ORANGE,	
	RGB_COLOR_GREEN,
	RGB_COLOR_BLUE
};
AT(.com_text.led_disp.table)
const u16 engegy_table[13] = {0x200,0x500,0x800,0x1000,0x1500,0x2000,0x3000,0x4000,0x6000,0x8000,0xB000,0xe000,0xffff};

#if 0
AT(.com_text.light_disp.table)
const u8 sequence_2_color_table[]=
{
	RGB_COLOR_YELLOW,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_PURPLE,
	RGB_COLOR_GREEN,
	RGB_COLOR_BLUE,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_LIGHT_PURPLE,
	RGB_COLOR_PINK
};
AT(.com_text.light_disp.table)
const u8 sequence_4_color_table[4][4]=
{
	{RGB_COLOR_MAGENTA,RGB_COLOR_LIGHT_BLUE},
	{RGB_COLOR_YELLOW,RGB_COLOR_GREEN},
	{RGB_COLOR_PINK,RGB_COLOR_PURPLE},
	{RGB_COLOR_MAGENTA,RGB_COLOR_GREEN,RGB_COLOR_YELLOW,RGB_COLOR_LIGHT_BLUE},
};
AT(.com_text.light_disp.table)
const u8 sequence_4_table_size[]=
{
	2,2,2,4
};
AT(.com_text.light_disp.table)
const u8 sequence_3a_color_table[]=
{
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_MAGENTA,
};
AT(.com_text.light_disp.table)
const u8 sequence_3b_color_table[]=
{
	RGB_COLOR_GREEN,
	RGB_COLOR_YELLOW,
	RGB_COLOR_GREEN,
	RGB_COLOR_YELLOW,
	RGB_COLOR_GREEN,
	RGB_COLOR_YELLOW,
};

AT(.com_text.light_disp.table)
const u8 sequence_4a_color_table[]=
{
	RGB_COLOR_MAGENTA,
	RGB_COLOR_LIGHT_BLUE,
};
AT(.com_text.light_disp.table)
const u8 sequence_4b_color_table[]=
{
	RGB_COLOR_YELLOW,
	RGB_COLOR_GREEN,
};
AT(.com_text.light_disp.table)
const u8 sequence_4c_color_table[]=
{
	RGB_COLOR_PINK,
	RGB_COLOR_PURPLE,
};
AT(.com_text.light_disp.table)
const u8 sequence_4d_color_table[]=
{
	RGB_COLOR_MAGENTA,
	RGB_COLOR_GREEN,
	RGB_COLOR_YELLOW,
	RGB_COLOR_LIGHT_BLUE,
};
AT(.com_text.light_disp.table)
const u8 sequence_7_color_table[]=
{
	RGB_COLOR_MAGENTA,
	RGB_COLOR_LIGHT_PURPLE,
	RGB_COLOR_YELLOW,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_GREEN,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_PINK,
	RGB_COLOR_PURPLE
};
AT(.com_text.light_disp.table)
const u8 sequence_8_color_table[]=
{
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_GREEN,
	RGB_COLOR_BLUE,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_PINK,
};

AT(.com_text.light_disp.table)
const u8 sequence_9_color_table[]=
{
	RGB_COLOR_YELLOW,
	RGB_COLOR_PINK,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_LIGHT_PURPLE,
	RGB_COLOR_PURPLE,
	RGB_COLOR_GREEN,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_BLUE,
};
AT(.com_text.light_disp.table)
const u8 sequence_11_color_table[]=
{
	RGB_COLOR_GREEN,
	RGB_COLOR_BLUE,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_LIGHT_PURPLE,
	RGB_COLOR_PINK,
	RGB_COLOR_YELLOW,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_PURPLE
};
AT(.com_text.light_disp.table)
const u8 sequence_12_color_table[]=
{
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_PINK,
	RGB_COLOR_BLUE,
	RGB_COLOR_LIGHT_PURPLE,
	RGB_COLOR_GREEN,
	RGB_COLOR_YELLOW,
	RGB_COLOR_PURPLE
};

AT(.com_text.light_disp.table)
const u8 sequence_13_color_table[]=
{
	RGB_COLOR_BLUE,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_GREEN,
	RGB_COLOR_PURPLE,
	RGB_COLOR_LIGHT_PURPLE,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_PINK,
	RGB_COLOR_YELLOW,
};
AT(.com_text.light_disp.table)
const u8 sequence_16a_color_table[]=
{
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_PINK,
	RGB_COLOR_OFF,
	RGB_COLOR_OFF,
	RGB_COLOR_OFF,
};
AT(.com_text.light_disp.table)
const u8 sequence_16_color_table[]=
{
	RGB_COLOR_OFF,
	RGB_COLOR_OFF,
	RGB_COLOR_OFF,
	RGB_COLOR_GREEN,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_YELLOW,
};

AT(.com_text.light_disp.table)
const u8 sequence_15_color_table[]=
{
	RGB_COLOR_BLUE,
	RGB_COLOR_LIGHT_BLUE,
	RGB_COLOR_GREEN,
	RGB_COLOR_PURPLE,
	RGB_COLOR_MAGENTA,
	RGB_COLOR_WHITE,
};
#endif
AT(.com_text.const)
const char print_buf[]="step:%d\n";


AT(.com_text.light_disp)
void rgb_buf_set(u8 color_index)
{
	//com_memset(rgb_light_buf,color_index,MAX_GRB_LED);
	memset(rgb_light_buf,color_index,MAX_GRB_LED);
}
AT(.text.light_disp)
void bsp_light_off(void)
{
	light_info.timer_start=0;
	memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);
}

AT(.text.light_disp)
void bsp_light_bt_pair_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=5;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);
}
AT(.com_text.light_disp)
void bsp_light_bt_pair(void)
{
	printf("light step:%d\n",light_info.light_step);
	if(!light_info.light_step)
	{
		light_info.light_step=1;
		memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	}
	else
	{
		memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);
		light_info.light_step=0;
	}
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=5;
}
AT(.text.light_disp)
void bsp_light_bt_connected_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	rgb_light_buf[light_info.light_step]=bt_connected_color_table[light_info.light_step];
	rgb_light_set((u8*)rgb_light_buf);
}
AT(.com_text.light_disp)
void bsp_light_bt_connected(void)
{
	light_info.light_step++;
	
	rgb_light_buf[light_info.light_step]=bt_connected_color_table[light_info.light_step];
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=1;
	if(light_info.light_step>=7)
	{
		light_info.timer_start=0;
		light_info.light_step=0;
	}
	
	
}
AT(.text.light_disp)
void bsp_light_bt_idle_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=5;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	rgb_light_buf[light_info.light_step]=bt_connected_color_table[light_info.light_step];
	rgb_light_set((u8*)rgb_light_buf);
}
AT(.com_text.light_disp)
void bsp_light_bt_idle(void)
{
	light_info.light_step++;
	if(light_info.light_step>7)
	{
		light_info.light_step=0;
	}
	memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	rgb_light_buf[light_info.light_step]=bt_connected_color_table[light_info.light_step];
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=5;
	
	
}

AT(.com_text.led_disp)
void rgb_led_push_music(u8 onoff)
{
	if(onoff)
	{
		memcpy(rgb_light_buf,bt_connected_color_table,MAX_GRB_LED);
	}
	else
	{
		memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	}
	rgb_light_set((u8*)rgb_light_buf);
}

AT(.text.light_disp)
void bsp_light_bt_play_init(void)
{
	grow_info.disp_start=0;
}
AT(.com_text.light_disp)
void bsp_light_bt_play(void)
{
	u32 energy;
	u8 i,cur_level=0;
	if(light_info.light_mode!=LIGHT_BT_PLAY)
	{
		return;
	}
	if(tick_check_expire(delay_ticks,50))
	{
		delay_ticks = tick_get();
		#if 0
		cur_level=get_random(6);
		#else
		energy = dac_pcm_pow_calc();
		//printf("energy:0x%x\n",energy);
		for(i=0;i<13;i++)
		{
			if(energy<engegy_table[i])
			{
				cur_level=i;
				break;
			}
		}
		#endif
		//printf("cur_level:%d->prev_level:%d\n",cur_level,prev_level);
		if(cur_level>prev_level)
		{
			rgb_led_push_music(0);
			#if 0
			if((cur_level-prev_level)&&(cur_level>2))
			{
				rgb_led_push_music(0);
			}
			else
			{
				rgb_led_push_music(1);
			}
			#endif
		}
		else
		{
			rgb_led_push_music(1);
		}
		prev_level=cur_level;
	}
	
	
}

#if 0
AT(.text.light_disp)
void bsp_light_Sequence_1_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	com_memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);

}


AT(.com_text.light_disp)
void bsp_light_Sequence_1(void)
{
	//printf(print_buf,light_info.light_step);
	//memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	if(light_info.light_step>4)
	{
		light_info.light_step=3;
	}
	rgb_buf_set(RGB_COLOR_OFF);
	switch(light_info.light_step)
	{
		case 0:
		    rgb_light_buf[LED_3]=RGB_COLOR_BLUE;
			rgb_light_buf[LED_6]=RGB_COLOR_BLUE;
			break;
		case 1:
		    rgb_light_buf[LED_2]=RGB_COLOR_BLUE;
			rgb_light_buf[LED_5]=RGB_COLOR_BLUE;
			break;
		case 2:
		    rgb_light_buf[LED_1]=RGB_COLOR_BLUE;
			rgb_light_buf[LED_4]=RGB_COLOR_BLUE;
			break;
		case 3:
			//com_memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
			break;
		case 4:
			com_memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);
			break;
	}
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step++;

}
AT(.text.light_disp)
void bsp_light_Sequence_2_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0x80;
	light_info.color_index=0;
	light_info.timer_start=1;
	grow_info.disp_start=2;
	rgb_buf_set(sequence_2_color_table[light_info.color_index]);
	rgb_light_set(rgb_light_buf);
	//printf("sequece 2# start!!\n");
}


AT(.com_text.light_disp)
void bsp_light_Sequence_2(void)
{
	//memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);

	light_info.time_out=1;
	if(light_info.light_step==0x80)
	{
		light_info.light_step=0;
	}
	else
	{
		light_info.light_step++;
		if(light_info.light_step>7)
		{
			light_info.light_step=1;
			light_info.color_index++;
			if(light_info.color_index>=sizeof(sequence_2_color_table))
			{
				light_info.color_index=0;
			}
		}
	}
	//printf(print_buf,light_info.light_step);
	switch(light_info.light_step)
	{
		case 0x80:
			//memset(rgb_light_buf,sequence_2_color_table[light_info.color_index],MAX_GRB_LED);
			//rgb_buf_set(sequence_2_color_table[light_info.color_index]);
			break;
		case 0:
			//rgb_buf_set(RGB_COLOR_OFF);
			light_info.time_out=14;
			light_info.color_index++;
			break;
		case 1:
			//rgb_buf_set(RGB_COLOR_OFF);
			rgb_light_buf[LED_6]=sequence_2_color_table[light_info.color_index];
			break;
		case 2:
			//rgb_light_buf[LED_6]=RGB_COLOR_OFF;
			rgb_light_buf[LED_5]=sequence_2_color_table[light_info.color_index];
			break;
		case 3:
			//rgb_light_buf[LED_5]=RGB_COLOR_OFF;
			rgb_light_buf[LED_4]=sequence_2_color_table[light_info.color_index];
			break;
		case 4:
			//rgb_light_buf[LED_4]=RGB_COLOR_OFF;
			rgb_light_buf[LED_1]=sequence_2_color_table[light_info.color_index];
			break;
		case 5:
			//rgb_light_buf[LED_1]=RGB_COLOR_OFF;
			rgb_light_buf[LED_2]=sequence_2_color_table[light_info.color_index];
			break;
		case 6:
			//rgb_light_buf[LED_2]=RGB_COLOR_OFF;
			rgb_light_buf[LED_3]=sequence_2_color_table[light_info.color_index];
			break;
		case 7:
			light_info.time_out=15;
			rgb_buf_set(sequence_2_color_table[light_info.color_index]);
			rgb_light_set(rgb_light_buf);
			#if 0
			delay_5ms(1);
			rgb_buf_set(sequence_2_color_table[light_info.color_index]);
			rgb_light_set(rgb_light_buf);
			delay_5ms(2);
			#endif
			//memset(rgb_light_buf,sequence_2_color_table[light_info.color_index],MAX_GRB_LED);
			break;
		case 8:
			light_info.time_out=24;
			rgb_buf_set(sequence_2_color_table[light_info.color_index]);
			//memset(rgb_light_buf,sequence_2_color_table[light_info.color_index],MAX_GRB_LED);
			break;
	}
	rgb_light_set(rgb_light_buf);
	light_info.time_cnt=0;



}
AT(.text.light_disp)
void bsp_light_Sequence_3a_init(void)
{
	light_info.timer_start=0;
	grow_info.disp_start=0;
	memcpy(rgb_light_buf,sequence_3a_color_table,MAX_GRB_LED);
	rgb_light_set(rgb_light_buf);
}
AT(.text.light_disp)
void bsp_light_Sequence_3b_init(void)
{
	light_info.timer_start=0;
	grow_info.disp_start=0;
	memcpy(rgb_light_buf,sequence_3b_color_table,MAX_GRB_LED);
	rgb_light_set(rgb_light_buf);
}
AT(.text.light_disp)
void bsp_light_Sequence_4_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
}
AT(.com_text.light_disp)
void bsp_light_Sequence_4(u8 mode)
{
	memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	if(light_info.light_step>2)
	{
		light_info.light_step=0;
		light_info.color_index++;
		if(light_info.color_index>=sequence_4_table_size[mode])
		{
			light_info.color_index=0;
		}
	}
	light_info.time_cnt=0;
	light_info.time_out=2;
	switch(light_info.light_step)
	{
		case 0:
			rgb_light_buf[LED_2]=sequence_4_color_table[mode][light_info.color_index];
			rgb_light_buf[LED_4]=sequence_4_color_table[mode][light_info.color_index];
		    rgb_light_buf[LED_6]=sequence_4_color_table[mode][light_info.color_index];
			break;
		case 1:
			rgb_light_buf[LED_1]=sequence_4_color_table[mode][light_info.color_index];
			rgb_light_buf[LED_3]=sequence_4_color_table[mode][light_info.color_index];
		    rgb_light_buf[LED_5]=sequence_4_color_table[mode][light_info.color_index];
			break;
	}
	rgb_light_set(rgb_light_buf);
	light_info.light_step++;
}

AT(.text.light_disp)
void bsp_light_Sequence_6a_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
}
AT(.com_text.light_disp)
void bsp_light_Sequence_6a(void)
{
	if(light_info.light_step>3)
	{
		light_info.light_step=0;
	}
	rgb_buf_set(RGB_COLOR_OFF);
	switch(light_info.light_step)
	{
		case 0:
			rgb_light_buf[LED_1]=RGB_COLOR_BLUE;
			rgb_light_buf[LED_4]=RGB_COLOR_BLUE;
			break;
		case 1:
			rgb_light_buf[LED_2]=RGB_COLOR_BLUE;
			rgb_light_buf[LED_5]=RGB_COLOR_BLUE;
			break;
		case 2:
			rgb_light_buf[LED_3]=RGB_COLOR_BLUE;
			rgb_light_buf[LED_6]=RGB_COLOR_BLUE;
			break;
		case 3:
			break;
		default:
			break;
	}
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step++;

}
AT(.text.light_disp)
void bsp_light_Sequence_6b_init(void)
{
	light_info.timer_start=0;
	grow_info.disp_start=1;
	grow_info.tick_cnt=0;
	grow_info.tick_start=1;
	memset(rgb_light_buf,RGB_COLOR_RED,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);
	printf("6b  time start!!\n");
}

AT(.text.light_disp)
void bsp_light_Sequence_6c_init(void)
{
	light_info.timer_start=0;
	grow_info.ticks_grow=0;
	grow_info.tick_cnt=0;
	grow_info.disp_start=1;
	grow_info.tick_start=0;
	memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);
	printf("6c  time start!!\n");
}
//sequence 6a中 bt connected blue on 2s
AT(.text.light_disp)
void bsp_light_Sequence_6a_1_init(void)
{
	light_info.timer_start=0;
	grow_info.ticks_grow=0;
	grow_info.disp_start=1;
	grow_info.tick_start=1;
	memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);
	printf("6a 1 time start!!\n");
}

//Sequence_6a&Sequence_6a light mode
AT(.com_text.light_disp)
void bsp_light_Sequence_6_timer(void)
{
	if((light_info.light_mode!=LIGHT_SEQUENCE_6B)&&(light_info.light_mode!=LIGHT_SEQUENCE_6A_1))
	{
		return;
	}
	if(tick_check_expire(grow_info.ticks_grow,1000))
	{
		grow_info.ticks_grow = tick_get();
		if(grow_info.tick_start)
		{
			//printf("6a 1 time start AAAA!!\n");
			grow_info.tick_start=0;
			return;
		}
		if(func_cb.sta==FUNC_BT)
		{
			bsp_set_light_mode(LIGHT_SEQUENCE_2);
		}
		else if(sys_cb.sfx_index!=0)
		{
			bsp_set_sfx_mode(sys_cb.sfx_index);
		}
		else
		{
			bsp_set_light_mode(LIGHT_SEQUENCE_2);
		}
	}
}

AT(.com_text.light_disp)
void bsp_light_Sequence_6C_timer(void)
{
	if(light_info.light_mode!=LIGHT_SEQUENCE_6C)
	{
		return;
	}
	if(tick_check_expire(grow_info.ticks_grow,250))
	{
		grow_info.ticks_grow = tick_get();
		//printf("6C time start CCCC!!\n");
		if(grow_info.tick_start)
		{
			grow_info.tick_start=0;
			return;
		}
		grow_info.tick_cnt++;
		if(grow_info.tick_cnt>8)
		{
			if(func_cb.sta==FUNC_BT)
			{
				bsp_set_light_mode(LIGHT_SEQUENCE_6A);
			}
			else if(sys_cb.sfx_index!=0)
			{
				bsp_set_sfx_mode(sys_cb.sfx_index);
			}
			else
			{
				bsp_set_light_mode(LIGHT_SEQUENCE_6A);
			}
			return;
		}
		if(grow_info.tick_cnt%2)
		{
			memset(rgb_light_buf,RGB_COLOR_BLUE,6);
		}
		else
		{
			memset(rgb_light_buf,RGB_COLOR_OFF,6);
		}
		rgb_light_set((u8*)rgb_light_buf);
	}
}

AT(.text.light_disp)
void bsp_light_Sequence_7_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	memset(rgb_light_buf,sequence_7_color_table[light_info.color_index],MAX_GRB_LED);
}


AT(.com_text.light_disp)
void bsp_light_Sequence_7(void)
{
	u8 next_color=0;
	if(light_info.light_step>6)
	{
		light_info.light_step=1;
		light_info.color_index++;
		if(light_info.color_index>(sizeof(sequence_7_color_table)-1))
		{
			light_info.color_index=0;
		}
	}
	//printf(print_buf,light_info.light_step);
	switch(light_info.light_step)
	{
		case 0:
			//memset(rgb_light_buf,sequence_7_color_table[light_info.color_index],6);
			break;
		case 1:
			rgb_light_buf[LED_1]=RGB_COLOR_OFF;
			rgb_light_buf[LED_4]=RGB_COLOR_OFF;
			break;
		case 2:
			rgb_light_buf[LED_2]=RGB_COLOR_OFF;
			rgb_light_buf[LED_5]=RGB_COLOR_OFF;
			break;
		case 3:
			rgb_light_buf[LED_3]=RGB_COLOR_OFF;
			rgb_light_buf[LED_6]=RGB_COLOR_OFF;
			break;
		case 4:
			if(light_info.color_index<(sizeof(sequence_7_color_table)-1))
			{
				next_color=light_info.color_index+1;
			}
			else
			{
				next_color=0;
			}
			rgb_light_buf[LED_1]=sequence_7_color_table[next_color];
			rgb_light_buf[LED_4]=sequence_7_color_table[next_color];
			break;
		case 5:
			if(light_info.color_index<(sizeof(sequence_7_color_table)-1))
			{
				next_color=light_info.color_index+1;
			}
			else
			{
				next_color=0;
			}
			rgb_light_buf[LED_2]=sequence_7_color_table[next_color];
			rgb_light_buf[LED_5]=sequence_7_color_table[next_color];
			break;
		case 6:
			if(light_info.color_index<(sizeof(sequence_7_color_table)-1))
			{
				next_color=light_info.color_index+1;
			}
			else
			{
				next_color=0;
			}
			rgb_light_buf[LED_3]=sequence_7_color_table[next_color];
			rgb_light_buf[LED_6]=sequence_7_color_table[next_color];
			break;
		default:
			break;
	}
	rgb_light_set(rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=2;
	light_info.light_step++;

}

AT(.text.light_disp)
void bsp_light_Sequence_8_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	rgb_buf_set(sequence_8_color_table[light_info.color_index]);
	rgb_light_set(rgb_light_buf);
	light_info.color_index++;
}
AT(.com_text.light_disp)
void bsp_light_Sequence_8(void)
{
	u8 next_color=0;
	//memset(rgb_light_buf,sequence_8_color_table[light_info.color_index],6);
	if(light_info.light_step>7)
	{
		light_info.light_step=1;
		light_info.color_index++;
		if(light_info.color_index>(sizeof(sequence_8_color_table)-1))
		{
			light_info.color_index=0;
		}
	}
	//rgb_buf_set(sequence_8_color_table[light_info.color_index]);
	switch(light_info.light_step)
	{
		case 0:
			break;
		case 1:
			rgb_light_buf[LED_1]=RGB_COLOR_OFF;
			break;
		case 2:
			rgb_light_buf[LED_1]=sequence_8_color_table[light_info.color_index];
			rgb_light_buf[LED_4]=RGB_COLOR_OFF;
			break;
		case 3:
			#if 0
			if(light_info.color_index<(sizeof(sequence_8_color_table)-1))
			{
				next_color=light_info.color_index+1;
			}
			else
			{
				next_color=0;
			}
			#endif
			rgb_light_buf[LED_4]=sequence_8_color_table[light_info.color_index];
			rgb_light_buf[LED_2]=RGB_COLOR_OFF;
			break;
		case 4:
			#if 0
			if(light_info.color_index<(sizeof(sequence_8_color_table)-1))
			{
				next_color=light_info.color_index+1;
			}
			else
			{
				next_color=0;
			}
			#endif
			rgb_light_buf[LED_2]=sequence_8_color_table[light_info.color_index];
			rgb_light_buf[LED_5]=RGB_COLOR_OFF;
			break;
		case 5:
			#if 0
			if(light_info.color_index<(sizeof(sequence_8_color_table)-1))
			{
				next_color=light_info.color_index+1;
			}
			else
			{
				next_color=0;
			}
			#endif
			rgb_light_buf[LED_5]=sequence_8_color_table[light_info.color_index];
			rgb_light_buf[LED_3]=RGB_COLOR_OFF;
			break;
		case 6:
			#if 0
			if(light_info.color_index<(sizeof(sequence_8_color_table)-1))
			{
				next_color=light_info.color_index+1;
			}
			else
			{
				next_color=0;
			}
			#endif
			rgb_light_buf[LED_3]=sequence_8_color_table[light_info.color_index];
			rgb_light_buf[LED_6]=RGB_COLOR_OFF;
			break;
		case 7:
			rgb_light_buf[LED_6]=sequence_8_color_table[light_info.color_index];
			break;
		default:
			break;
	}
	rgb_light_set(rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=3;
	light_info.light_step++;

}


AT(.text.light_disp)
void bsp_light_Sequence_9_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=sizeof(sequence_9_color_table)-1;
	light_info.timer_start=1;
	grow_info.disp_start=0;
}
AT(.com_text.light_disp)
void bsp_light_Sequence_9(void)
{
	u8 next_color=0,i;
	if(light_info.light_step>7)
	{
		light_info.light_step=0;
		light_info.color_index++;
		if(light_info.color_index>(sizeof(sequence_9_color_table)-1))
		{
			light_info.color_index=0;
		}
	}
	if(light_info.color_index<(sizeof(sequence_9_color_table)-1))
	{
		next_color=light_info.color_index+1;
	}
	else
	{
		next_color=0;
	}
	light_info.time_out=3;
	for(i=0;i<6;i++)
	{
		if(i%2)
		{
			rgb_light_buf[i]=sequence_9_color_table[next_color];
		}
		else
		{
			rgb_light_buf[i]=sequence_9_color_table[light_info.color_index];
		}

	}
	rgb_light_set(rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step++;

}

AT(.text.light_disp)
void bsp_light_Sequence_10_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=sizeof(sequence_9_color_table)-1;
	light_info.timer_start=1;
	grow_info.disp_start=0;
}
AT(.com_text.light_disp)
void bsp_light_Sequence_10(void)
{
	u8 next_color=0,i;
	if(light_info.light_step>7)
	{
		light_info.light_step=0;
		light_info.color_index++;
		if(light_info.color_index>(sizeof(sequence_9_color_table)-1))
		{
			light_info.color_index=0;
		}
	}
	if(light_info.color_index<(sizeof(sequence_9_color_table)-1))
	{
		next_color=light_info.color_index+1;
	}
	else
	{
		next_color=0;
	}
	for(i=0;i<6;i++)
	{
		if(i<3)
		{
			rgb_light_buf[i]=next_color;
		}
		else
		{
			rgb_light_buf[i]=sequence_9_color_table[light_info.color_index];
		}

	}

	rgb_light_set(rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=3;
	light_info.light_step++;

}

AT(.text.light_disp)
void bsp_light_Sequence_11_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	rgb_buf_set(sequence_11_color_table[light_info.color_index]);
	rgb_light_set(rgb_light_buf);
	light_info.color_index=1;
}
AT(.com_text.light_disp)
void bsp_light_Sequence_11(void)
{
	u8 next_color=0;
	//memset(rgb_light_buf,sequence_11_color_table[light_info.color_index],6);
	//rgb_buf_set(sequence_11_color_table[light_info.color_index]);
	if(light_info.light_step>6)
	{
		light_info.light_step=1;
		light_info.color_index++;
		if(light_info.color_index>(sizeof(sequence_8_color_table)-1))
		{
			light_info.color_index=0;
		}
	}
	if(light_info.color_index<(sizeof(sequence_9_color_table)-1))
	{
		next_color=light_info.color_index+1;
	}
	else
	{
		next_color=0;
	}
	switch(light_info.light_step)
	{
		case 0:
			break;
		case 1:
			rgb_light_buf[LED_6]=sequence_11_color_table[next_color];
			break;
		case 2:
			rgb_light_buf[LED_5]=sequence_11_color_table[next_color];
			break;
		case 3:
			rgb_light_buf[LED_4]=sequence_11_color_table[next_color];
			break;
		case 4:
			rgb_light_buf[LED_1]=sequence_11_color_table[next_color];
			break;
		case 5:
			rgb_light_buf[LED_2]=sequence_11_color_table[next_color];
			break;
		case 6:
			rgb_light_buf[LED_3]=sequence_11_color_table[next_color];
			break;
		default:
			break;
	}
	rgb_light_set(rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step++;

}




AT(.com_text.light_disp)
void bsp_light_Sequence_12(void)
{
	//printf("grow step:%d\n",light_info.light_step);

	if(light_info.color_index>=(sizeof(sequence_12_color_table)-1))
	{
		light_info.color_index=0;
	}
	if(light_info.light_step>2)
	{
		light_info.light_step=1;
	}
	#if 1
	switch(light_info.light_step)
	{
		case 0:
			grow_info.next_color_table[LED_1]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_3]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_5]=sequence_12_color_table[light_info.color_index];
			grow_info.disp_start=1;
			break;
		case 1:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_1]=grow_info.next_color_table[LED_1];
			//grow_info.cur_color_table[LED_3]=grow_info.next_color_table[LED_3];
			//grow_info.cur_color_table[LED_5]=grow_info.next_color_table[LED_5];
			grow_info.next_color_table[LED_1]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_3]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_5]=RGB_COLOR_OFF;
			light_info.color_index++;
			grow_info.next_color_table[LED_2]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_4]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_6]=sequence_12_color_table[light_info.color_index];
			break;
		case 2:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_2]=grow_info.next_color_table[LED_2];
			//grow_info.cur_color_table[LED_4]=grow_info.next_color_table[LED_4];
			//grow_info.cur_color_table[LED_6]=grow_info.next_color_table[LED_6];
			light_info.color_index++;
			grow_info.next_color_table[LED_2]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_4]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_6]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_1]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_3]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_5]=sequence_12_color_table[light_info.color_index];
			break;

		default:
			break;
	}
	light_info.light_step++;
	#else
	switch(light_info.light_step)
	{
		case 0:
			grow_info.next_color_table[LED_1]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_3]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_5]=sequence_12_color_table[light_info.color_index];
			grow_info.disp_start=1;
			break;
		case 1:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_1]=grow_info.next_color_table[LED_1];
			//grow_info.cur_color_table[LED_3]=grow_info.next_color_table[LED_3];
			//grow_info.cur_color_table[LED_5]=grow_info.next_color_table[LED_5];
			grow_info.next_color_table[LED_1]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_3]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_5]=RGB_COLOR_OFF;
			light_info.color_index++;
			grow_info.next_color_table[LED_2]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_4]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_6]=sequence_12_color_table[light_info.color_index];
			break;
		case 2:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_2]=grow_info.next_color_table[LED_2];
			//grow_info.cur_color_table[LED_4]=grow_info.next_color_table[LED_4];
			//grow_info.cur_color_table[LED_6]=grow_info.next_color_table[LED_6];
			light_info.color_index++;
			grow_info.next_color_table[LED_2]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_4]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_1]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_5]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_6]=sequence_12_color_table[light_info.color_index];
			break;
		case 3:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_1]=grow_info.next_color_table[LED_1];
			//grow_info.cur_color_table[LED_5]=grow_info.next_color_table[LED_5];
			//grow_info.cur_color_table[LED_6]=grow_info.next_color_table[LED_6];
			light_info.color_index++;
			grow_info.next_color_table[LED_1]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_5]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_6]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_2]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_3]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_4]=sequence_12_color_table[light_info.color_index];
			break;
		case 4:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_2]=grow_info.next_color_table[LED_2];
			//grow_info.cur_color_table[LED_3]=grow_info.next_color_table[LED_3];
			//grow_info.cur_color_table[LED_4]=grow_info.next_color_table[LED_4];
			light_info.color_index++;
			grow_info.next_color_table[LED_2]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_3]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_4]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_3]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_4]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_5]=sequence_12_color_table[light_info.color_index];
			break;
		case 5:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_3]=grow_info.next_color_table[LED_3];
			//grow_info.cur_color_table[LED_4]=grow_info.next_color_table[LED_4];
			//grow_info.cur_color_table[LED_5]=grow_info.next_color_table[LED_5];
			light_info.color_index++;
			grow_info.next_color_table[LED_3]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_4]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_5]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_1]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_2]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_6]=sequence_12_color_table[light_info.color_index];
			break;
		case 6:
			com_memcpy(grow_info.cur_color_table,grow_info.next_color_table,6);
			//grow_info.cur_color_table[LED_1]=grow_info.next_color_table[LED_1];
			//grow_info.cur_color_table[LED_2]=grow_info.next_color_table[LED_2];
			//grow_info.cur_color_table[LED_6]=grow_info.next_color_table[LED_6];
			light_info.color_index++;
			grow_info.next_color_table[LED_1]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_2]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_6]=RGB_COLOR_OFF;
			grow_info.next_color_table[LED_1]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_3]=sequence_12_color_table[light_info.color_index];
			grow_info.next_color_table[LED_5]=sequence_12_color_table[light_info.color_index];
			break;
		default:
			break;
	}
	light_info.light_step++;

	#endif
}

AT(.text.light_disp)
void bsp_light_Sequence_12_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=0;
	light_info.timer_start=0;
	grow_info.disp_start=0;
	grow_info.ticks_grow=0;
	grow_info.disp_start=1;
	memset(grow_info.cur_color_table,RGB_COLOR_OFF,6);
	memset(grow_info.next_color_table,RGB_COLOR_OFF,6);
	grow_info.fade_steps=0;
	grow_info.color_switch_time=25;//500ms 周期，20 ms timer
	memset(rgb_light_buf,RGB_COLOR_OFF,6);
	rgb_light_set(rgb_light_buf);
	delay_ms(50);
	bsp_light_Sequence_12();
}


AT(.text.light_disp)
void bsp_light_Sequence_13_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=1;
	light_info.color_index=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	memset(rgb_light_buf,RGB_COLOR_OFF,6);
}

AT(.com_text.light_disp)
void bsp_light_Sequence_13(void)
{
	u8 next_color=0;
	if(light_info.light_step>8)
	{
		light_info.light_step=4;
		light_info.color_index++;
		if(light_info.color_index>(sizeof(sequence_13_color_table)-1))
		{
			light_info.color_index=0;
		}
	}
	//printf(print_buf,light_info.color_index);
	switch(light_info.light_step)
	{
		case 0:
			//memset(rgb_light_buf,RGB_COLOR_OFF,6);
			break;
		case 1:
			rgb_light_buf[LED_1]=sequence_13_color_table[light_info.color_index];
			rgb_light_buf[LED_6]=sequence_13_color_table[light_info.color_index];
			break;
		case 2:
			rgb_light_buf[LED_2]=sequence_13_color_table[light_info.color_index];
			rgb_light_buf[LED_5]=sequence_13_color_table[light_info.color_index];
			break;
		case 3:
			rgb_light_buf[LED_3]=sequence_13_color_table[light_info.color_index];
			rgb_light_buf[LED_4]=sequence_13_color_table[light_info.color_index];
			light_info.color_index++;
			break;
		case 4:
			rgb_light_buf[LED_1]=RGB_COLOR_OFF;
			rgb_light_buf[LED_6]=RGB_COLOR_OFF;
			break;
		case 5:
			rgb_light_buf[LED_2]=RGB_COLOR_OFF;
			rgb_light_buf[LED_5]=RGB_COLOR_OFF;
			break;
		case 6:
			rgb_light_buf[LED_1]=sequence_13_color_table[light_info.color_index];
			rgb_light_buf[LED_6]=sequence_13_color_table[light_info.color_index];
			rgb_light_buf[LED_3]=RGB_COLOR_OFF;
			rgb_light_buf[LED_4]=RGB_COLOR_OFF;			
			break;
		case 7:
			
			rgb_light_buf[LED_2]=sequence_13_color_table[light_info.color_index];
			rgb_light_buf[LED_5]=sequence_13_color_table[light_info.color_index];
			break;
		case 8:
			rgb_light_buf[LED_3]=sequence_13_color_table[light_info.color_index];
			rgb_light_buf[LED_4]=sequence_13_color_table[light_info.color_index];
			break;
		default:
			break;
	}
	rgb_light_set(rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=3;
	light_info.light_step++;

}
AT(.text.light_disp)
void bsp_light_Sequence_14_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;
	//memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);

}

AT(.com_text.light_disp)
void bsp_light_Sequence_14(void)
{
	//printf("light_step:%d\n",light_info.light_step);
	if(light_info.light_step>5)
	{
		//light_info.light_mode=0;
		//printf("light off!!!\n");
		rgb_buf_set(RGB_COLOR_OFF);
		rgb_light_set((u8*)rgb_light_buf);
		light_info.timer_start=0;
		return;
	}
	switch(light_info.light_step)
	{
		case 0:
		    //memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);
			rgb_buf_set(RGB_COLOR_BLUE);
			break;
		case 1:
		    //memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
		    rgb_buf_set(RGB_COLOR_OFF);
			break;
		case 2:
			//memset(rgb_light_buf,RGB_COLOR_BLUE,MAX_GRB_LED);
			rgb_buf_set(RGB_COLOR_BLUE);
			break;
		case 3:
			rgb_light_buf[LED_1]=RGB_COLOR_OFF;
			rgb_light_buf[LED_4]=RGB_COLOR_OFF;
			break;
		case 4:
			rgb_light_buf[LED_2]=RGB_COLOR_OFF;
			rgb_light_buf[LED_5]=RGB_COLOR_OFF;
			break;
		case 5:
			rgb_light_buf[LED_3]=RGB_COLOR_OFF;
			rgb_light_buf[LED_6]=RGB_COLOR_OFF;
			break;
		default:
			return;
	}
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step++;

}
AT(.text.light_disp)
void bsp_light_Sequence_16a_init(void)
{
	light_info.timer_start=0;
	grow_info.disp_start=0;
	memcpy(rgb_light_buf,sequence_16a_color_table,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);
}
AT(.text.light_disp)
void bsp_light_Sequence_16_init(void)
{
	light_info.timer_start=0;
	grow_info.disp_start=0;
	memcpy(rgb_light_buf,sequence_16_color_table,MAX_GRB_LED);
	rgb_light_set((u8*)rgb_light_buf);
}
AT(.text.light_disp)
void bsp_light_Sequence_17_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.disp_start=0;

}
AT(.com_text.light_disp)
void bsp_light_Sequence_17(void)
{
	//printf("light_step:%d\n",light_info.light_step);
	if(light_info.light_step>1)
	{
		light_info.light_step=0;
	}
	switch(light_info.light_step)
	{
		case 0:
		    //memset(rgb_light_buf,RGB_COLOR_MAGENTA,MAX_GRB_LED);
			rgb_buf_set(RGB_COLOR_MAGENTA);
			break;
		case 1:
		   // memset(rgb_light_buf,RGB_COLOR_OFF,MAX_GRB_LED);
			rgb_buf_set(RGB_COLOR_OFF);
			break;
		default:
			return;
	}
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step++;

}

u8 random_num;
u8 random_color_index;

AT(.com_text.light_disp)
void bsp_get_random_color(void)
{
	u8 led_random_num,color_ramdon_num;
	u8 num_cnt=0,tmp_data;
	while(1)
	{
		led_random_num=get_random(6);
		if(led_random_num>=3&&led_random_num<=5)
		{
			break;
		}
	}
	color_ramdon_num=get_random(6);
	random_color_index=sequence_15_color_table[color_ramdon_num];
	random_num=0;
	//printf("led num:%d->color index:%d\n",led_random_num,cur_color_index);
	while(1)
	{
		tmp_data=get_random(6);
		if((random_num&(0x01<<tmp_data))==0)
		{
			num_cnt++;
			random_num|=0x01<<tmp_data;
		}
		if(num_cnt>=led_random_num)
		{
			break;
		}
	}
}
AT(.com_text.light_disp)
void bsp_light_Sequence_15_random_color_timer(void)
{
	if(light_info.light_mode!=LIGHT_SEQUENCE_15)
	{
		return;
	}
	if(tick_check_expire(grow_info.ticks_grow,200))
	{
		grow_info.ticks_grow = tick_get();
		bsp_get_random_color();
	}
}

AT(.text.light_disp)
void bsp_light_Sequence_15_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.timer_start=1;
	grow_info.ticks_grow=0;
	grow_info.disp_start=1;
	bsp_get_random_color();

}
AT(.com_text.light_disp)
void bsp_light_Sequence_15(void)
{
	u8 i;
	rgb_buf_set(RGB_COLOR_OFF);
	for(i=0;i<6;i++)
	{
		if(random_num&(0x01<<i))
		{
			rgb_light_buf[i]=random_color_index;
		}
	}
	rgb_light_set((u8*)rgb_light_buf);
	light_info.time_cnt=0;
	light_info.time_out=2;
}

AT(.text.light_disp)
void bsp_light_Sequence_20_init(void)
{
	light_info.timer_start=0;
	grow_info.disp_start=0;
	memset(rgb_light_buf,RGB_COLOR_OFF,6);
	rgb_light_set((u8*)rgb_light_buf);
}


AT(.text.light_disp)
void bsp_light_Sequence_18_init(void)
{
	light_info.time_cnt=0;
	light_info.time_out=1;
	light_info.light_step=0;
	light_info.color_index=0;
	grow_info.ticks_grow=0;
	light_info.timer_start=0;
	memcpy(grow_info.cur_color_table,rgb_light_buf,6);
	memset(grow_info.next_color_table,RGB_COLOR_OFF,6);
	grow_info.fade_steps=0;
	grow_info.color_switch_time=50;//500ms 周期，20 ms timer
	grow_info.disp_start=1;
}
AT(.com_text.light_disp)
void bsp_light_Sequence_12_timer(void)
{
	if((light_info.light_mode!=LIGHT_SEQUENCE_12)&&(light_info.light_mode!=LIGHT_SEQUENCE_18))
	{
		return;
	}

	if(tick_check_expire(grow_info.ticks_grow,20))
	{
		grow_info.ticks_grow = tick_get();
		grow_info.fade_steps++;
		if(light_info.light_mode==LIGHT_SEQUENCE_12)
		{
			//printf("fade_steps:%d\n",grow_info.fade_steps);
			if(display_glow_mode(&grow_info))
			{
				bsp_light_Sequence_12();
			}
		}
		else if(light_info.light_mode==LIGHT_SEQUENCE_18)
		{
			if(display_glow_mode(&grow_info))
			{
				grow_info.disp_start=0;
			}
		}

	}
}

#endif

AT(.com_text.light_disp)
void bsp_light_Sequence_display(void)
{
	if(!light_info.timer_start)
	{
		return;
	}
	light_info.time_cnt++;
	if(light_info.time_cnt<light_info.time_out)
	{
		return;
	}
	#if 1
	switch(light_info.light_mode)
	{
		case LIGHT_BT_PAIR:
			bsp_light_bt_pair();
			break;
		case LIGHT_BT_CONNECTED:
			bsp_light_bt_connected();
			break;
		case LIGHT_BT_IDLE:
			bsp_light_bt_idle();
			break;
		case LIGHT_BT_PLAY:
			break;
		default:
			break;
	}
	#else
	switch(light_info.light_mode)
	{
		case LIGHT_SEQUENCE_1:
			bsp_light_Sequence_1();
			break;
		case LIGHT_SEQUENCE_2:
			bsp_light_Sequence_2();
			break;
		case LIGHT_SEQUENCE_3A:
			//bsp_light_Sequence_3a();
			break;
		case LIGHT_SEQUENCE_3B:
			//bsp_light_Sequence_3a();
			break;
		case LIGHT_SEQUENCE_4A:
			bsp_light_Sequence_4(0);
			break;
		case LIGHT_SEQUENCE_4B:
			bsp_light_Sequence_4(1);
			break;
		case LIGHT_SEQUENCE_4C:
			bsp_light_Sequence_4(2);
			break;
		case LIGHT_SEQUENCE_4D:
			bsp_light_Sequence_4(3);
			break;
		case LIGHT_SEQUENCE_6A:
			bsp_light_Sequence_6a();
			break;
		case LIGHT_SEQUENCE_6B:
			//bsp_light_Sequence_6b();
			break;
		case LIGHT_SEQUENCE_6C:
			//bsp_light_Sequence_6c();
			break;
		case LIGHT_SEQUENCE_7:
			bsp_light_Sequence_7();
			break;
		case LIGHT_SEQUENCE_8:
			bsp_light_Sequence_8();
			break;
		case LIGHT_SEQUENCE_9:
			bsp_light_Sequence_9();
			break;
		case LIGHT_SEQUENCE_10:
			bsp_light_Sequence_10();
			break;
		case LIGHT_SEQUENCE_11:
			bsp_light_Sequence_11();
			break;
		case LIGHT_SEQUENCE_13:
			bsp_light_Sequence_13();
			break;
		case LIGHT_SEQUENCE_14:
			bsp_light_Sequence_14();
			break;
		case LIGHT_SEQUENCE_15:
			bsp_light_Sequence_15();
			break;
		case LIGHT_SEQUENCE_17:
			bsp_light_Sequence_17();
			break;

		default:
			break;
	}
	#endif
}
u32 light_timer=0;
AT(.com_text.light_disp)
void bsp_light_timer(void)
{
	#if 1
	if(tick_check_expire(light_timer,100))
	{
		light_timer = tick_get();
		if(light_info.light_mode!=0)
		{
			bsp_light_Sequence_display();
		}
	}
	#else
	if(light_info.light_mode!=0)
		{
			bsp_light_Sequence_display();
		}
	#endif

}
AT(.com_text.light_disp)
void bsp_sequence_display_timer(void)
{
	if(!sys_cb.light_onoff)
	{
		return;
	}
	bsp_light_timer();
	bsp_light_bt_play();
	if(!grow_info.disp_start)
	{
		return;
	}
	//bsp_light_Sequence_6_timer();
	//bsp_light_Sequence_6C_timer();
	//bsp_light_Sequence_15_random_color_timer();
	//bsp_light_Sequence_12_timer();

}
AT(.text.light_disp)

void bsp_light_mode_init(void)
{
	printf("light mode:%d\n",light_info.light_mode);
	#if 1
	switch(light_info.light_mode)
	{
		case LIGHT_BT_PAIR:
			bsp_light_bt_pair_init();
			break;
		case LIGHT_BT_CONNECTED:
			bsp_light_bt_connected_init();
			break;
		case LIGHT_BT_IDLE:
			bsp_light_bt_idle_init();
			break;
		case LIGHT_BT_PLAY:
			bsp_light_bt_play_init();
			break;
		case LIGHT_SET_OFF:
			bsp_light_off();
			break;
		default:
			break;
	}
	#else
	switch(light_info.light_mode)
	{
		case LIGHT_SEQUENCE_1:
			bsp_light_Sequence_1_init();
			break;
		case LIGHT_SEQUENCE_2:
			bsp_light_Sequence_2_init();
			break;
		case LIGHT_SEQUENCE_3A:
			bsp_light_Sequence_3a_init();
			break;
		case LIGHT_SEQUENCE_3B:
			bsp_light_Sequence_3b_init();
			break;
		case LIGHT_SEQUENCE_4A:
		case LIGHT_SEQUENCE_4B:
		case LIGHT_SEQUENCE_4C:
		case LIGHT_SEQUENCE_4D:
			bsp_light_Sequence_4_init();
			break;
		case LIGHT_SEQUENCE_6A:
			bsp_light_Sequence_6a_init();
			break;
		case LIGHT_SEQUENCE_6A_1:
			bsp_light_Sequence_6a_1_init();
			break;
		case LIGHT_SEQUENCE_6B:
			bsp_light_Sequence_6b_init();
			break;
		case LIGHT_SEQUENCE_6C:
			bsp_light_Sequence_6c_init();
			break;
		case LIGHT_SEQUENCE_7:
			bsp_light_Sequence_7_init();
			break;
		case LIGHT_SEQUENCE_8:
			bsp_light_Sequence_8_init();
			break;
		case LIGHT_SEQUENCE_9:
			bsp_light_Sequence_9_init();
			break;
		case LIGHT_SEQUENCE_10:
			bsp_light_Sequence_10_init();
			break;
		case LIGHT_SEQUENCE_11:
			bsp_light_Sequence_11_init();
			break;
		case LIGHT_SEQUENCE_12:
			bsp_light_Sequence_12_init();
			break;
		case LIGHT_SEQUENCE_13:
			bsp_light_Sequence_13_init();
			break;
		case LIGHT_SEQUENCE_14:
			bsp_light_Sequence_14_init();
			break;
		case LIGHT_SEQUENCE_15:
			bsp_light_Sequence_15_init();
			break;
		case LIGHT_SEQUENCE_16A:
			bsp_light_Sequence_16a_init();
			break;
		case LIGHT_SEQUENCE_16:
			bsp_light_Sequence_16_init();
			break;
		case LIGHT_SEQUENCE_17:
			bsp_light_Sequence_17_init();
			break;
		case LIGHT_SEQUENCE_18:
			bsp_light_Sequence_18_init();
			break;

		case LIGHT_SEQUENCE_20:
			bsp_light_Sequence_20_init();
            break;
		default:
		break;
	}
	#endif
}
#if 1
const u8 test_mode[]=
{
	LIGHT_SEQUENCE_2,
    LIGHT_SEQUENCE_7,
    LIGHT_SEQUENCE_8,
    LIGHT_SEQUENCE_11,
    LIGHT_SEQUENCE_12,
    LIGHT_SEQUENCE_13,
};
u8 test_mode_index=0;
const u8 test_index[]=
{
	RGB_COLOR_YELLOW,
	RGB_COLOR_PINK,
	RGB_COLOR_MAGENTA,
};

void test_color(void)
{
	printf("test_mode_index:%d\n",test_mode_index);
	#if 1
	if(test_mode_index>2)
	{
		test_mode_index=0;
	}
	//rgb_light_buf[test_mode_index]=RGB_COLOR_WHITE+test_mode_index;
	memset(rgb_light_buf,RGB_COLOR_WHITE+test_mode_index+1,MAX_GRB_LED);
	delay_ms(10);
	rgb_light_set((u8*)rgb_light_buf);
	delay_ms(50);
	test_mode_index++;
	
	#else

	if(test_mode_index>=6)
	{
		//rgb_light_buf[test_mode_index]=RGB_COLOR_RED;
		test_mode_index=0;
	}
	light_info.light_mode=test_mode[test_mode_index];
	bsp_light_mode_init();
	test_mode_index++;
	#endif
}
#endif
AT(.text.light_disp.table)
const u8 sfx_all_light_mode_table[]=
{
	LIGHT_SEQUENCE_7,
	LIGHT_SEQUENCE_8,
	LIGHT_SEQUENCE_9,
	LIGHT_SEQUENCE_10,
	LIGHT_SEQUENCE_11,
	LIGHT_SEQUENCE_12,
	LIGHT_SEQUENCE_13,
	LIGHT_SEQUENCE_2,
	LIGHT_SEQUENCE_20,
};
AT(.text.light_disp)
void bsp_set_light_mode(u8 light_mode)
{
	printf("%s light_mode:%d\n", __func__,light_mode);
	light_info.light_mode=light_mode;
	if(sys_cb.light_onoff==0)
	{
		return;
	}
	#if 0
	if(sys_cb.sfx_index)
	{
		if(func_cb.sta==FUNC_BT)
		{
			printf("bt status:%d\n",bt_get_status());
			if((bt_get_status() == BT_STA_SCANNING)||(bt_get_status() == BT_STA_IDLE)||light_mode==LIGHT_SEQUENCE_6A_1||light_mode==LIGHT_SEQUENCE_6B
				||light_mode==LIGHT_SEQUENCE_6C||light_mode==LIGHT_SEQUENCE_1||light_mode==LIGHT_SEQUENCE_14)
			{
				light_info.light_mode=light_mode;
			}
			else
			{
				light_info.light_mode=sfx_all_light_mode_table[sys_cb.sfx_index-1];
			}
		}
		else
		{
			if(light_mode==LIGHT_SEQUENCE_1||light_mode==LIGHT_SEQUENCE_14)
			{
				light_info.light_mode=light_mode;
			}
			else
			{
				return;
			}
			
			
		}
	}
	else
	{
		light_info.light_mode=light_mode;
	}
	#endif
	bsp_light_mode_init();
}
AT(.text.light_disp)
void bsp_set_light_onoff(void)
{
	sys_cb.light_onoff=!sys_cb.light_onoff;
	if(sys_cb.light_onoff)
	{
		bsp_set_light_mode(light_info.light_mode);
	}
	else
	{
		bsp_light_off();
	}
}

AT(.text.light_disp)
void bsp_set_sfx_mode(u8 light_mode)
{
	return;
}

